<?php
    
    require_once( MODEL_DIR . "Model.class.php");
    
    class PlaylistModel extends Model{
        
        protected $query;
        
        public function __construct()
        {
            parent::__construct();
        }
        
        
        public function get_grupo_show(){
            
            $hoje = date("Y-m-d H:i:s");
                                            
            $set_where = "status = 1 AND data_exibicao <= '$hoje'";
            $set_order = "data_exibicao DESC";
            $set_limit = 1;
            return parent::read("santander_grupo",$set_where,$set_order,$set_limit,1);
            
        }
        
        public function get_grupo_show_2(){
            
            $hoje = date("Y-m-d H:i:s");
                                            
            $set_where = "status = 1 AND data_exibicao <= '$hoje'";
            $set_order = "data_exibicao DESC";
            $set_limit = 2;
            return parent::read("santander_grupo",$set_where,$set_order,$set_limit,1);
            
        }
        
        public function get_playlist_show($grupo_fk){
            
            $sql = "SELECT  sp.*, sp.id AS id_playlist, sm.id AS idartista, sm.artista, sm.musica, sm.imagem FROM `santander_playlist` sp, `santander_musicas` sm WHERE grupo_fk = $grupo_fk AND sp.musica_id = sm.id ORDER BY sp.posicao ASC LIMIT 25;";
             
            return parent::read_join($sql);
        }
        
       
        
        public function get_grupo_flash_show(){
            
            $hoje = date("Y-m-d H:i:s");
                                            
            $set_where = "status = 1 AND data_exibicao <= '$hoje'";
            $set_order = "data_exibicao DESC";
            $set_limit = 1;
            return parent::read("santander_grupo_flashback",$set_where,$set_order,$set_limit,1);
            
        }  
        
        public function get_flashback_show($grupo_fk){
            
            $sql = "SELECT  sp.*, sp.id AS id_playlist, sm.id AS idartista, sm.artista, sm.musica, sm.imagem FROM `santander_flashback` sp, `santander_musicas` sm WHERE grupo_fk = $grupo_fk AND sp.musica_id = sm.id ORDER BY sp.posicao ASC LIMIT 25;";
             
            return parent::read_join($sql);
        }
        
        public function get_sorteados(){
            
            $hoje = date("Y-m-d H:i:s");
                                            
            $set_where = "status = 1 AND data_exibicao <= '$hoje'";
            $set_order = "data_exibicao DESC";
            $set_limit = 2;
            return parent::read("santander_resultado",$set_where,$set_order,$set_limit,1);
            
        }
        
        public function get_sorteados_total(){
            
            $hoje = date("Y-m-d H:i:s");
                                            
            $set_where = "status = 1 AND data_exibicao <= '$hoje'";
            $set_order = "data_exibicao DESC";
            $set_limit = null;
            return parent::read("santander_resultado",$set_where,$set_order,$set_limit,1);
            
        } 
        
        public function get_sorteados_total_id($id){
            
            $hoje = date("Y-m-d H:i:s");
                                            
            $set_where = "status = 1 AND data_exibicao <= '$hoje' AND id < $id";
            $set_order = "data_exibicao DESC";
            $set_limit = 2;
            return parent::read("santander_resultado",$set_where,$set_order,$set_limit,1);
            
        }   
               
        public function get_lancamentos(){
            
            $hoje = date("Y-m-d H:i:s");
            #echo $hoje;                                
            $set_where = "status = 1 AND data_exibicao <= '$hoje'";
            $set_order = "data_exibicao DESC";
            $set_limit = 1;
            return parent::read("santander_lancamentos",$set_where,$set_order,$set_limit,1);
            
        }
        
        public function get_nome_musica($id){
            $set_where = "status = 1 AND id = '$id'";
            $set_order = null;
            $set_limit = 1;
            return parent::read("santander_musicas",$set_where,$set_order,$set_limit,1);
        }
        
        public function salvar_voto($nome,$id_musica,$hora,$tipo,$usuario){
            
            $nnome = addslashes($nome);

            $r = Array("nome" => "$nnome", "id_musica" => "$id_musica", 
            "legal" => "1", "hora_pedido" => "$hora", "tipo_voto" => "$tipo","usuario_fk" => "$usuario");

            $query = parent::insert("santander_musicas_mensal",$r);
            return $query;
            
        }
        
        
        
        #Promocao
        public function get_promocao($id)
        {
           
            $set_where = "pub_idPublicacaoPK = $id";
            $set_order = null;
            $set_limit = 1;
            return parent::read("jb_promocao",$set_where,$set_order,$set_limit,1);
        }
        
        public function usuarioParticipante($usuarioPK,$promocaoPK)
        {
           
            $set_where = "FKusuario = $usuarioPK AND FKpromocao = $promocaoPK";
            $set_order = null;
            $set_limit = 1;
            return parent::read("jb_participante_promocao",$set_where,$set_order,$set_limit,1);
        }
        
        public function cadastrarUsuarioPromocao($usuarioPK,$promocaoPK,$resposta)
        {
            $data = date("Y-m-d H:i:s");
           
            $r = Array("FKusuario" => "$usuarioPK", "FKpromocao" => "$promocaoPK", 
            "resposta" => "$resposta", "sorteado" => "0", "FKgrupoParticipante" => "0","data" => "$data");

            $query = parent::insert("jb_participante_promocao",$r);
            return $query;
            
        }
        
        public function check_email($email){
                
            $set_where = "cad_email = '$email'";
            $set_order = null;
            $set_limit = 1;
            return parent::read("jb_cadastro",$set_where,$set_order,$set_limit,1);
            
        }
        
        public function cadastro($array_usuario)
        {
            $query = parent::insert("jb_cadastro",$array_usuario);
            return $query;
            
        }
        
        
           
       
        
        
        
    }        
?>